package org.dru.clay.respository.artifact;

public class Module implements Comparable<Module> {
	private final Group group;
	private final Artifact artifact;

	public Module(Group group, Artifact artifact) {
		this.group = group;
		this.artifact = artifact;
	}

	public Group getGroup() {
		return group;
	}

	public Artifact getArtifact() {
		return artifact;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((artifact == null) ? 0 : artifact.hashCode());
		result = prime * result + ((group == null) ? 0 : group.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Module other = (Module) obj;
		if (artifact == null) {
			if (other.artifact != null)
				return false;
		} else if (!artifact.equals(other.artifact))
			return false;
		if (group == null) {
			if (other.group != null)
				return false;
		} else if (!group.equals(other.group))
			return false;
		return true;
	}

	@Override
	public int compareTo(Module o) {
		int ret = group.compareTo(o.group);
		if (ret != 0) {
			return ret;
		}
		return artifact.compareTo(o.artifact);
	}

	@Override
	public String toString() {
		return group + "." + artifact;
	}
}
